package jdk7;

import java.io.FileInputStream;
import java.io.IOException;

public class SuppressException {
	/**
	 * 记录异常，不被淹没 addSuppressed
	 */
	public void read(String filename) throws Exception {
		FileInputStream input = null;
		IOException readException = null;
		try {
			input = new FileInputStream(filename);
		} catch (IOException ex) {
			readException = ex;
		} finally {
			if (input != null) {
				try {
					input.close();
				} catch (IOException ex) {
					if (readException == null) {
						readException = ex;
					} else {
						// 使用java7的
						readException.addSuppressed(ex);
					}
				}
			}
			if (readException != null) {
				throw new Exception(readException);
			}
		}
	}
}
